#include "LM75.h"

uint8_t LM75_temps[NR_LM75_SENSORS];

void LM75_init(void)
{
	for(uint8_t loopCntr = 0; loopCntr <= NR_LM75_SENSORS-1; loopCntr++)
	{
		LM75_temps[loopCntr] = 0;
	}
	TWI_init();
}

static uint16_t LM75_getTemp(uint8_t adress)
{
	uint16_t ret = 0;

	if(!TWI_start(adress)){
		ret = (TWI_readAck()<<1);
		if(TWI_readNak()&0x80)
			ret++;
		TWI_stop();
	}
	return ret;
}

void LM75_readAllSensors(void)
{
	for(uint8_t loopCntr = 0; loopCntr < NR_LM75_SENSORS; loopCntr++)
	{
		LM75_temps[loopCntr] = LM75_getTemp(LM75_BASEADRESS);//+loopCntr);
	}
}
